let http = require('http');
const { URL } = require('url');

// 解析url
const parseURL = ()=>{

}
// 定义URL调用对象
const use = (path,callback)=>{
    
}
// 根据URL映射到对应的函数
const handlerRouteMap = (path)=>{

}
const server = http.createServer((req,res)=>{
    console.log(req.url)
    console.log(req.method)
    console.log(req.statusMessage)
    console.log(req.trailers)
    console.log(req.rawTrailers)
    console.log(req.body)
    const url = req.url
    req.on('data',function(data){
        console.log('data: ', data);
    });
    // res.end('ok')
    res.writeHead(200, {"Content-type" : "text/html"});
    res.write("<h1>Node.js</h1>");
    res.end("<p>Hello World</p>");
    // res.destroy('distory')
})
const listen = (port,callback)=>{
    server.listen(port);
    if(callback){
        callback()
    }
}

const app = ()=>{
    return {
        listen,
        use
    }
}
module.exports = app